package com.bcbim.operation_maintenance.department.service;

import com.bcbim.common.sys.Code;
import com.bcbim.common.sys.Constant;
import com.bcbim.operation_maintenance.department.mapper.DepartmentMapper;
import com.bcbim.operation_maintenance_interface.department.dao.DepartmentDAO;
import com.bcbim.operation_maintenance_interface.department.dto.DepartmentNameCheckDTO;
import com.bcbim.operation_maintenance_interface.department.service.DepartmentService;
import com.bcbim.operation_maintenance_interface.department.vo.DepartmentDetailVO;
import com.bcbim.operation_maintenance_interface.space.dto.SpaceColorTypeDTO;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 部门实现类
 * @Author xuehao
 * @Date 2022/03/09  16:44
 * @Version V1.0
 **/
@Service(timeout = 60 * 1000, group = "department", version = "1.0.0")
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    /**
     * 业务部下拉
     *
     * @author xuehao
     * @createDate 2022/3/9 15:27
     * @retuen List<Code>
     */
    @Override
    public List<Code> pullBusinessDepartment(String projectId) {
        return departmentMapper.pullBusinessDepartment(projectId);
    }

    /**
     * 新增部门
     *
     * @param departmentDAO
     * @author xuehao
     * @createDate 2022/3/9 15:37
     * @retuen int
     */
    @Override
    public int insertDepartment(DepartmentDAO departmentDAO) {
        return departmentMapper.insertDepartment(departmentDAO);
    }

    /**
     * 编辑部门
     *
     * @param departmentDAO
     * @author xuehao
     * @createDate 2022/3/9 15:45
     * @retuen int
     */
    @Override
    public int updateDepartment(DepartmentDAO departmentDAO) {
        return departmentMapper.updateDepartment(departmentDAO);
    }

    /**
     * 查询部门详情
     *
     * @author xuehao
     * @createDate 2022/3/9 16:21
     * @retuen DepartmentDetailVO
     */
    @Override
    public DepartmentDetailVO getDepartment(String id) {
        return departmentMapper.getDepartment(id);
    }

    /**
     * 判断部门名称是否重复
     *
     * @param departmentNameCheckDTO
     * @author xuehao
     * @createDate 2022/3/9 16:42
     * @retuen int
     */
    @Override
    public int checkDepartmentName(DepartmentNameCheckDTO departmentNameCheckDTO) {
        return departmentMapper.checkDepartmentName(departmentNameCheckDTO);
    }

    /**
     * 颜色下拉
     *
     * @author xuehao
     * @createDate 2022/3/13 14:57
     * @retuen Code
     */
    @Override
    public List<Code> pullColour() {
        return departmentMapper.pullColour();
    }

    /**
     * 查询颜色图例
     *
     * @author xuehao
     * @createDate 2022/3/13 15:41
     * @retuen List<Code>
     */
    @Override
    public List<Code> selectColourCutLine(SpaceColorTypeDTO spaceColorTypeDTO) {
        List<Code> list = new ArrayList<>();
        if (StringUtils.isNotEmpty(spaceColorTypeDTO.getCode())) {
            switch (spaceColorTypeDTO.getCode()) {
                case Constant.COLOUR_CATEGORY:
                    list = departmentMapper.colourCategory(spaceColorTypeDTO);
                    break;
                case Constant.COLOUR_TYPE:
                    list = departmentMapper.colourType(spaceColorTypeDTO);
                    break;
                case Constant.COLOUR_BUSINESS:
                    list = departmentMapper.colourBusiness(spaceColorTypeDTO);
                    break;
                case Constant.COLOUR_DEPARTMENT:
                    list = departmentMapper.colourDepartment(spaceColorTypeDTO);
                    break;
                case Constant.COLOUR_OCCUPATION:
                    Code code1 = new Code();
                    code1.setCode("可占用");
                    code1.setValue("#000");
                    list.add(code1);
                    break;
                default:
            }
        }
        return list;
    }

    @Override
    public String getUnassignedId(String businessDepartmentId, String unassignedName) {
        return departmentMapper.getUnassignedId(businessDepartmentId, unassignedName);
    }
}
